var webpack = require('webpack');
var path=require('path');
var ExtractTextPlugin = require("extract-text-webpack-plugin");
var BrowserSyncPlugin = require('browser-sync-webpack-plugin');
var hostconfig=require('./config/hostconfig');
console.log(__dirname);
module.exports = {
    entry: {
        main: [
            'webpack-dev-server/client?http://'+hostconfig.host+':'+hostconfig.port,//资源服务器地址
            'webpack/hot/only-dev-server',
            './src/index.jsx'
        ]
    }
    ,
    output: {
        path:'./dist/',  //打包输出的路径
        filename: 'main.js',            //打包后的名字
        publicPath: 'http://'+hostconfig.host+':'+hostconfig.port+'/dist/', //html引用路径，在这里是本地地址。
        //crossOriginLoading:'anonymous'//可以跨域
    },
    devServer:{
        //contentBase:'',
        //devtool:'source-map',
        colors:true,
        hot:true,
        inline:true,
        host:hostconfig.host,
        port:hostconfig.port
        /*proxy: {
            '/api*': {
                target: 'http://localhost:'+hostconfig.serverProt,
                secure: false
            }
        }*/
    },
    resolve: {
        extensions: ['', '.js', '.jsx','less','css']//自动添加后缀
    },
    module: {
        loaders:[
            { test: /\.js$/,
                exclude: /node_modules/,
                loaders: ['babel?presets[]=react,presets[]=es2015,presets[]=stage-0']
            },
            { test: /\.jsx$/,
                exclude: /node_modules/,
                loaders: ['jsx-loader?harmony','babel?presets[]=react,presets[]=es2015,presets[]=stage-0']
            },
            {
                test:/\.less$/,
                exclude: /node_modules/,
                loaders:['style','css','less']
            },
            {
                test:/\.css$/,
                exclude: /node_modules/,
                loaders:['style','css']
            },
            {
                test: /\.(png|jpg)$/,
                exclude: /node_modules/,
                loader: 'url-loader'
            }

        ]
    },
    externals:{
        //'echarts':'./lib/echarts.js'
    },
    alias: {
        'react-redux': path.resolve(__dirname, '/node_modules/react-redux/dist/react-redux.js'),
        'react-router': path.resolve(__dirname, '/node_modules/react-router/lib/index.js'),
        'redux': path.resolve(__dirname, '/node_modules/redux/dist/redux.js')
    },
    devtool:'source-map',
    plugins: [

        new webpack.DefinePlugin({
            'process.env.NODE_ENV': '"development"'
        }),
        //new ExtractTextPlugin('./src/css/[name].css'),
        new webpack.HotModuleReplacementPlugin(),
        new BrowserSyncPlugin(
            // BrowserSync options
            {
                // browse to http://localhost:3000/ during development
                host: hostconfig.host,
                port: hostconfig.proxy,
                // proxy the Webpack Dev Server endpoint
                // (which should be serving on http://localhost:3100/)
                // through BrowserSync
                proxy: 'http://'+hostconfig.host+':'+hostconfig.serverProt+'/',
            },
            // plugin options
            {
                // prevent BrowserSync from reloading the page
                // and let Webpack Dev Server take care of this
                /*server:{
                    ['']
                },*/
                reload:false

            }
        )
    ]
};
